home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gekikoh Dennoh Club 5
/
Gekikoh Dennoh Club Vol. 5 (Japan).7z
/
Gekikoh Dennoh Club Vol. 5 (Japan) (Track 01).bin
/
docs
/
rakup
/
match06.doc
< prev
next >
Wrap
Lisp/Scheme
|
1998-10-03
|
14KB
|
457 lines
ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬
(MATCH06.DOC)
é¿ïCèyé▓é¡éτé¡âvâìâOâëâ~âôâOôⁿûσ ö╘èOò╥ üuâGâLâXâpü[âgâVâXâeâÇé╠ì∞ɼüv
ìLêΣü@É╜
ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬ä¬
ü¢è╚ê╒âGâLâXâpü[âgâVâXâeâÇé╠ì∞ɼ
é╗éΩé┼é═üAÄ└ì█é╔âvâìâOâëâÇé≡ì∞é┴é─éóé½é▄é╖üBé▄é╕é═É▀é╠ÆΦï`é⌐éτé┼é╖üBÉ▀
é═âNâëâX Rule é┼ò\é╡üAô¬òöé╠ÅqîΩé≡ò\é╖âVâôâ{âïé╠æ«É½âèâXâgé╠æ«É½û╝ RULE
é╔èiö[é╡é▄é╖üB
List 34 : ÄûÄ└é╞ïKæÑé╠ÆΦï`
1 (defclass Rule ()
2 (var-list ; ò╧ÉöâèâXâg
3 clause)) ; É▀
âXâìâbâg var-list é═üAÉ▀ clause é┼ÄgéφéΩé─éóéΘò╧Éöé≡âèâXâgé╔é▄é╞é▀é─âZâb
âgé╡é▄é╖üBé▒éΩé═üAÉ▀é╠ò╧Éöé≡ÉVé╡éóâVâôâ{âïé╔Æuè╖é╖éΘÄ₧é╔Ägéóé▄é╖üBé▒é╠Åê
ù¥é═âüâ\âbâh copy-clasue é┼ìséóé▄é╖üB
List 35 : É▀é≡âRâsü[é╖éΘ
1 (defmethod copy-clause ((r Rule))
2 (with-slots (var-list clause) r
3 (sublis
4 (if var-list
5 (mapcar #'(lambda (var) (cons var (gensym))) var-list))
6 clause)))
é▒é╠Åêù¥é═ sublis é≡Ägéªé╬è╚ÆPé┼é╖é╦üBsublis é═ÿAæzâèâXâgé¬ nil é╠ÅΩìçé═üA
ê°Éöé╠âèâXâgé≡é╗é╠é▄é▄ò╘é╡é▄é╖üBvar-list é¬ nil é╠ÅΩìçé═ clause é≡ò╘é╖é▒
é╞é╔é╚éΦé▄é╖üB
ăé═üAÉ▀é≡æ«É½âèâXâgé╔ôoÿ^é╖éΘÅêù¥é≡ì∞éΦé▄é╖üBè╓Éöû╝é═ assert é┼é╖üB
List 36 : É▀é╠ôoÿ^
1 (defun assert (clause)
2 (check-clause clause)
3 (let ((predicate (car (car clause))))
4 (putprop predicate
5 (cons (make-rule clause)
6 (get predicate 'RULE))
7 'RULE)))
é▄é╕üAcheck-clause é┼É▀é╠ì\æóé≡â`âFâbâNé╡é▄é╖üBăé╔üAô¬òöé╠ÅqîΩé≡ĵéΦÅo
é╡é─ò╧Éö predicate é╔âZâbâgé╡é▄é╖üBÉ▀é═ÅqîΩ predicate é╠æ«É½ RULE é╔âZâb
âgé╡é▄é╖üBâNâëâX Rule é╠âCâôâXâ^âôâXé≡ make-rule é┼ì∞ɼé╡üAôoÿ^é│éΩé─éó
éΘÉ▀é╔Æ╟ë┴é╡é▄é╖üB
List 37 : É▀é╠â`âFâbâN
1 (defun check-clause (clause)
2 (dolist (x clause)
3 (if (or (not (consp x))
4 (variablep (car x))
5 (not (symbolp (car x))))
6 (error "É▀é╔ÅqîΩé¬éáéΦé▄é╣é± ~A\n" clause))))
É▀é╠â`âFâbâNé═è╚ÆPé┼é╖üBclause é╠ùvæfé¬âèâXâgé┼üAé╗é╠æµ 1 ùvæfé¬ÅqîΩé╞é╡
é─öFé▀éτéΩéΘâVâôâ{âïüAé┬é▄éΦüAâVâôâ{âïé╛é»éΩé╟éαò╧Éöé┼é═é╚éóé▒é╞é≡èmöFé╡
é▄é╖üB3 ìsû┌é╠ if é┼üAx é¬âèâXâgé┼é╚éóüAx é╠ CAR é¬ò╧ÉöüAé▄é╜é═âVâôâ{âï
é┼é╚éóÅΩìçé═üAerror é┼âGâëü[âüâbâZü[âWé≡ò\Īé╡é▄é╖üB
List 38 : Rule é≡ì∞éΘ
1 (defun make-rule (clause)
2 (make-instance 'Rule
3 'var-list (collect-variable clause nil)
4 'clause clause))
make-rule é═è╚ÆPé┼é╖üBcollect-variable é┼ clause é╠ò╧Éöé≡ÅWé▀é─âXâìâbâg
var-list é╔âZâbâgé╡üAclause é≡âXâìâbâg clause é╔âZâbâgé╖éΘé╛é»é┼é╖üB
ăé═üAÉ▀é⌐éτò╧Éöé≡ÅWé▀éΘ collect-variable é≡ì∞éΦé▄é╖üB
List 39 : É▀é┼Ägùpé│éΩé─éóéΘò╧Éöé≡ÅWé▀éΘ
1 (defun collect-variable (clause var-list)
2 (cond
3 ((variablep clause)
4 (pushnew clause var-list))
5 ((atom clause) var-list)
6 (t (collect-variable
7 (cdr clause)
8 (collect-variable (car clause) var-list)))))
æµ 2 ê°Éö var-list é╔ò╧Éöé≡ÅWé▀üAé╗é╠îïë╩é≡ò╘é╡é▄é╖üBì┼Åëé╔î─é╤Åoé╖Ä₧
é═üAvar-list é╔é═ nil é≡âZâbâgé╡é─é¿é½é▄é╖üBê°Éö clause é═ car é╞ cdr é┼
ò¬ë≡é╡é▄é╖üB8 ìsû┌é┼üAclause é╠ CAR òö é╔ collect-varibale é≡ôKùpé╡üAé╗
é╠ò╘éΦÆlé¬ 6 ìsû┌é╠ collect-variable é╔ù^éªéτéΩüACDR òöé╠ò╧Éöé≡ÆTé╡é▄é╖üB
3 ìsû┌é┼üAò╧Éöé≡î⌐é┬é»é╜éτ var-list é╓âZâbâgé╡é▄é╖üBpushnew é≡Ägé┴é─éó
éΘé╠é┼üAô»é╢ò╧Éöé≡èiö[é╖éΘé▒é╞é═éáéΦé▄é╣é±üBclause é¬âAâgâÇé┼éáéΩé╬üAé▒
éΩê╚Åπò¬ë≡é┼é½é╚éóé╠é┼ var-list é≡ò╘é╡é▄é╖üB
ü¢É▀é╠Ä└ìs
ăé═üAâpâ^ü[âôâ}âbâ`âôâOé╞âoâbâNâgâëâbâNé≡ìséñÅêù¥é≡ì∞ɼé╡é▄é╖üBé▄é╕üA
è┬ï½é≡ò\é╖âNâëâX Env é≡ì─ôxĪé╡é▄é╖üB
List 32 : Ä└ìsè┬ï½é╠ÆΦï`
1 (defclass Env ()
2 (goal ; âSü[âïÉ▀
3 rule-list ; ÅqîΩé╔ÆΦï`é│éΩé─éóéΘÉ▀
4 exec-rule ; Ä└ìsÆåé╠É▀
5 exec-env ; ì∞ɼé╡é╜è┬ï½üiâXâ^âbâNé╔é╚éΘüj
6 binding)) ; æ⌐ö¢é╡é╜ò╧Éö
ì┼Åëé╔ Env é╠âCâôâXâ^âôâXé≡É╢ɼé╖éΘ make-env é≡ì∞éΦé▄é╖üB
List 40 : Ä└ìsè┬ï½é╠ì∞ɼ
1 (defun make-env (pattern)
2 (make-instance 'Env
3 'goal pattern
4 'rule-list (get (car pattern) 'RULE)
5 'binding 'call))
ê°Éö pattern é╔é═É▀é╞Å╞ìçé╖éΘâpâ^ü[âôüA(ÅqîΩ ê°Éö ... ê°Éö) é╞éóéñî`Ä«
é╠âfü[â^é¬ù^éªéτéΩé▄é╖üBé▒éΩé≡ goal é╔âZâbâgé╡üAÅqîΩé╠æ«É½ RULE é⌐éτÉ▀é≡
ĵéΦÅoé╡é─ rule-list é╔âZâbâgé╡é▄é╖üBé╗éΩé⌐éτüAì┼Åëé╠î─é╤Åoé╡é┼éáéΘé▒é╞
é≡Īé╖é╜é▀üAbinding é╔ call é≡âZâbâgé╡é▄é╖üB
É▀é╠Ä└ìsé═üAăé╔Īé╖âNâëâX Env é╠âüâ\âbâhé┼ìséóé▄é╖üB
exec-clause : É▀é╠Ä└ìsüBCall é╞ Redo é╠ÉUéΦò¬é»üB
select-rule : É▀é╠æIæ≡é╞Ä└ìsüB
unify-head : âSü[âïé╞ô¬òöé╠âåâjâtâBâPü[âVâçâôé≡ìséñüB
exec-body : æ╠òöé╠Ä└ìsüBì─ÄÄìsé┼é═è┬ï½é≡é╜é╟é┴é─éóé¡üB
exec-clause é≡ì─ïAî─é╤Åoé╡é╖éΘüB
É▀é╠Ä└ìsé═ exec-clause é⌐éτÄné▄éΦé▄é╖üBexec-clause é═âXâìâbâg goal é╔
âZâbâgé│éΩé╜âpâ^ü[âôé╞É▀é≡Å╞ìçé╡é▄é╖üB
List 41 : É▀é╠Ä└ìs
1 (defmethod exec-clasue ((e Env))
2 (with-slots (rule-list binding) e
3 (let ((result 'fail))
4 (if (eq binding 'call)
5 (if rule-list
6 (setq result (select-rule e)))
7 (if (eq 'fail (setq result (exec-body e)))
8 (setq result (select-rule e))))
9 (if (eq result 'fail)
10 (clear-binding binding)
11 result))))
4 ìsû┌é┼üAbinding é¬ call é┼éáéΩé╬ì┼Åëé╠î─é╤Åoé╡é┼é╖üB5 ìsû┌é┼üArule-
list é╔ïKæÑé¬âZâbâgé│éΩé─éóéΘé⌐â`âFâbâNé╡é▄é╖üBïKæÑé¬é╚é»éΩé╬ fail é╞é╚
éΦé▄é╖üBăé╔ select-rule é┼üAgoal é╞êΩÆvé╖éΘô¬òöé≡Ä¥é┬ïKæÑé≡æIæ≡é╡üAé╗éΩ
é≡Ä└ìsé╡é▄é╖üB
binding é¬ call ê╚èOé╠âfü[â^é┼éáéΩé╬üAì─ÄÄìs(Redo) é╠ÅΩìçé┼é╖üBEnv é╠
âXâìâbâg exec-env é╔âZâbâgé│éΩé─éóéΘè┬ï½é≡é╜é╟éΘé╜é▀üA7 ìsû┌é┼ exec-body
é≡î─é╤Åoé╡é▄é╖üBéαé╡üAexec-body é¬ fail é≡ò╘é╡é╜éτüAé▒é▒é¬ì┼îπé╔Ä└ìsé│éΩ
é╜è┬ï½é╚é╠é┼üAăé╠ïKæÑé≡æIæ≡é╖éΘé╜é▀ select-rule é≡î─é╤Åoé╡é▄é╖üB
Ä└ìsîïë╩é═ result é╔âZâbâgé╡é▄é╖é¬üA9 ìsû┌é┼é╗é╠îïë╩é≡â`âFâbâNé╡é▄é╖üB
éαé╡ fail é┼éáéΩé╬üAclear-binding é≡î─é╤Åoé╡é─üAò╧Éöæ⌐ö¢é≡âNâèâAé╡é─é⌐éτ
fail é≡ò╘é╡é▄é╖üBé╗éñé┼é╚é»éΩé╬ result é≡é╗é╠é▄é▄ò╘é╡é▄é╖üB
ăé═üAselect-rule é≡Éαû╛é╡é▄é╖üB
List 42 : É▀é╠æIæ≡é╞Ä└ìs
1 (defmethod select-rule ((e Env))
2 (with-slots (exec-rule) e
3 (let ((result 'fail))
4 (while
5 (and (listp (setq result (unify-head e)))
6 exec-rule)
7 (push (make-env (car exec-rule)) exec-env)
8 (if (listp (setq result (exec-body e)))
9 (return)))
10 result)))
É▀é╠æIæ≡é═ 5 ìsû┌é╠ unify-head é┼ìséóé▄é╖üBunify-head é╠ò╘éΦÆlé¬âèâXâg
é┼éáéΩé╬üAâåâjâtâBâPü[âVâçâôé═ɼî≈é╡é╜é▒é╞é¬éφé⌐éΦé▄é╖üBé▒é╠ÅΩìçüAnil éα
ɼî≈é╚é╠é┼ listp é┼ö╗Æfé╡é─éóé▄é╖üBunify-head é═ goal é╞ïKæÑé╠Å╞ìçé¬É¼î≈
é╡é╜ÅΩìçüAïKæÑé╠æ╠òöé≡ exec-rule é╔âZâbâgé╡é▄é╖üB6 ìsû┌é┼üAéαé╡ exec-rule
é¬ nil é┼éáéΩé╬üAÄ└ìsé╖éΘæ╠òöé¬é╚éóüuÄûÄ└üvé╚é╠é┼üAwhile âïü[âvé≡ö▓é»é─
result é≡ò╘é╡é▄é╖üB
7 ìsû┌é┼üAÄ└ìsé╖éΘæ╠òöé¬éáéΩé╬üAmake-env é┼ì┼Åëé╠âSü[âïé≡Ä└ìsé╖éΘé╜é▀
é╠è┬ï½é≡ì∞ɼé╡é─ exec-env é╔âZâbâgé╡é▄é╖üBexec-body é═ì─ÄÄìsé┼éαô«ì∞é╖éΘ
éµéñé╔üAexec-env é╔èiö[é│éΩé─éóéΘè┬ï½é╔æ╬é╡é─üAexec-clause é≡ôKùpé╖éΘéµ
éñé╔ì∞éτéΩé─éóé▄é╖üBé▒é╠é╜é▀üAì┼Åëé╠î─é╤Åoé╡é┼é═ exec-env é╔è┬ï½é≡âZâbâg
é╡é▄é╖üBÅ┌é╡éóÉαû╛é═ exec-body é┼ìséóé▄é╖üB8 ìsû┌é┼üAæ╠òöé≡Ä└ìsé╖éΘé╜é▀
exec-body é≡î─é╤Åoé╡é▄é╖üBé╗é╠îïë╩é¬É¼î≈é┼éáéΩé╬üAreturn é┼ while âïü[âv
é≡ö▓é»é─üAì┼îπé┼ result é≡ò╘é╡é▄é╖üB
ăé═üAunify-head é≡Éαû╛é╡é▄é╖üB
List 43 : âSü[âïé╞ïKæÑé╠ô¬òöé≡Å╞ìçé╖éΘ
1 (defmethod unify-head ((e Env))
2 (with-slots (goal rule-list exec-rule binding) e
3 (let ((result 'fail) now-rule)
4 (clear-binding binding)
5 (while rule-list
6 (setq now-rule (copy-clause (pop rule-list)))
7 (when
8 (listp (setq result (unify goal (pop now-rule) nil)))
9 (setq exec-rule now-rule
10 binding result)
11 (return)))
12 result)))
é▄é╕ 4 ìsû┌é┼üAclear-binding é┼æ⌐ö¢é│éΩé╜ò╧Éöé¬éáéΩé╬âNâèâAé╡é▄é╖üBă
é╔üArule-list é╠Æåé⌐éτ goal é╞Å╞ìçé╖éΘÉ▀é≡î⌐é┬é»é▄é╖üBé▄é╕ 6 ìsû┌é╠ pop
é┼ rule-list é⌐éτÉ▀é≡ĵéΦÅoé╡üAcopy-clause é┼ò╧Éöé≡ gensym é┼ì∞é┴é╜âVâô
â{âïé╔Æuè╖é╡üAé╗éΩé≡ now-rule é╔âZâbâgé╡é▄é╖üBé╗éΩé⌐éτ 8 ìsû┌é┼üAgoal é╞
now-rule é╠ô¬òöé≡ unify é┼âåâjâtâBâPü[âVâçâôé╡é▄é╖üBnow-rule é╔ pop é≡ôK
ùpé╡é─éóéΘé╠é┼üAnow-rule é╔é═æ╠òöé╡é⌐Äcé┴é─éóé╚éóé▒é╞é╔Æìê╙é╡é─é¡é╛é│éóüB
é╗é╠îïë╩é¬É¼î≈é┼éáéΩé╬üA9 ìsû┌é╠ setq é┼Äcé┴é╜æ╠òöé≡ exec-rule é╔âZâbâg
é╡üAîïë╩é≡ binding é╔âZâbâgé╡é▄é╖üBé╗é╡é─üAreturn é┼ while âïü[âvé≡ÆEÅo
é╡é▄é╖üBrule-list é¬ nil é╔é╚éΩé╬üAÆTé╖É▀é¬û│é¡é╚é┴é╜é╠é┼ fail é≡ò╘é╖é▒
é╞é╔é╚éΦé▄é╖üB
ăé═üAexec-body é≡Éαû╛é╡é▄é╖üB
List 44 : æ╠òöé╠Ä└ìs
1 (defun exec-body (env)
2 (with-slots (exec-env exec-rule) env
3 (let ((max-state (length exec-rule))
4 (result 'fail)
5 now-state)
6 (while exec-env
7 (setq result (exec-clasue (car exec-env)))
8 (cond
9 ((eq 'fail result)
10 (pop exec-env))
11 ((= max-state (setq now-state (length exec-env)))
12 (return))
13 (t (push (make-env (elt exec-rule now-state)) exec-env))))
14 result)))
exec-body é═æ╠òöé╠Ä└ìsé≡ÆSôûé╡üAì─ÄÄìsé┼é═ exec-env é╔èiö[é│éΩé─éóéΘè┬
ï½é≡é╜é╟éΘé▒é╞éαìséóé▄é╖üBé▒é╠é╜é▀üAì┼Åëé╠î─é╤Åoé╡é┼é═üAexec-env é╔Ä└ìs
è┬ï½é≡âZâbâgé╡é─é¿é⌐é╚éóé╞ô«ì∞é╡é▄é╣é±üB
æ╠òöé╠Ä└ìsé═üAé╗é▒é╔èiö[é│éΩé─éóéΘâSü[âïé¬æSé─ɼî≈é╡é╜Ä₧é╔üAé╗é╠ïKæÑé¬
ɼî≈é╞ö╗Æfé│éΩé▄é╖üBé▄é╕üAâSü[âïé╠æìÉöé≡ max-state é╔âZâbâgé╡é▄é╖üBăé╔üA
exec-env é╔è┬ï½é¬éáéΘè╘é═ while âïü[âvé┼æ╠òöé╠Ä└ìsé≡ìséóé▄é╖üB
éαé╡éαüAexec-env é╔è┬ï½é¬é╚éóÅΩìçé═üAexec-body é═fail é≡ò╘é╡é▄é╖üBé╗é╠
ÅΩìçé═üAexec-clause é┼ select-rule é¬Ä└ìsé│éΩüAé╗é╠è┬ï½é╔é¿é»éΘăé╠É▀é¬
æIæ≡é│éΩé▄é╖üB
7 ìsû┌é┼üAexec-env é╠ɵô¬é╔èiö[é│éΩé─éóéΘè┬ï½é╔æ╬é╡é─üAexec-clasue é≡
ôKùpé╡é▄é╖üBì┼Åëé╠î─é╤Åoé╡é╠ÅΩìçé═üAselect-rule é┼ì┼Åëé╠âSü[âïé╠Ä└ìsè┬ï½
é¬ exec-env é╔âZâbâgé│éΩé─éóéΘé╠é┼üAé╗é╠è┬ï½é╔ê┌ô«é╡é─âSü[âïé╞É▀é╠Å╞ìçé¬
ìséφéΩé▄é╖üB
ì─ÄÄìsé╠ÅΩìçüAexec-env é╠ɵô¬é╔é═ì┼îπé╔Ä└ìsé│éΩé╜è┬ï½é¬âZâbâgé│éΩé─éó
é▄é╖üBé▒é╠è┬ï½é╔æ╬é╡é─ exec-clause é≡ôKùpé╖éΩé╬üAé╗é╠è┬ï½é╔ê┌ô«é╖éΘé▒é╞
é¬é┼é½é▄é╖üBé▒éΩé≡îJéΦò╘é╖é▒é╞é┼üAêΩö╘ì┼îπé╔Ä└ìsé╡é╜è┬ï½é╓é╜é╟éΦÆàé¡é▒é╞
é¬é┼é½éΘé╠é┼é╖üB
9 ìsû┌é┼üAexec-clause é╠Ä└ìsé¬ fail é┼éáéΩé╬üAé╗é╠Ä└ìsè┬ï½é≡ exec-env
é⌐éτìφÅ£é╡é▄é╖üBé╖éΘé╞üAexec-env é╔é═é╗é╠æOé╔Ä└ìsé╡é╜è┬ï½é¬Åoé─é¡éΘé╠é┼üA
é╗éΩé╔æ╬é╡é─ exec-clause é≡Ä└ìsé╡é▄é╖üBé╜é╞éªé╬üAì┼Åëé╠î─é╤Åoé╡é╠ÅΩìçüA
1 ö╘û┌é╠âSü[âïé¬É¼î≈é╡é─éαüAăé╠âSü[âïé¬Ä╕ösé╡é╜éτüA1 ö╘û┌é╠âSü[âïé╔âoâb
âNâgâëâbâNé╡é╚éóé╞éóé»é▄é╣é±üBé▒é╠ô«ì∞é═ì─ÄÄìsé╠ÅΩìçé╞ô»é╢é┼é╖é╦üBé┬é▄éΦüA
æ╠òöé╠Ä└ìsé╞ì─ÄÄìsüiâoâbâNâgâëâbâNüjé═üAêΩæ╠é╞é╚é┴é─ô«ì∞é╡é╚éóé╞éóé»é╚éó
é╠é┼é╖üBé▒é╠ô«ì∞é≡ìséñé╠é¬ exec-body é┼éáéΦüACall é╞ Redo é╠ù╝ò√é⌐éτî─é╤
Åoé│éΩéΘé╠é┼é╖üB
11 ìsû┌é┼üAæ╠òöé≡æSé─Ä└ìsé╡é╜é⌐â`âFâbâNé╡é▄é╖üBexec-env é╔èiö[é│éΩé─éó
éΘè┬ï½é╠î┬Éö(now-state)é¬ max-state é╔é╚éΩé╬üAæSé─é╠âSü[âïé≡Ä└ìsé╡é╜é▒é╞
é¬éφé⌐éΦé▄é╖üBreturn é≡ò]ë┐é╡é─ while âïü[âvé≡ÆEÅoé╡é▄é╖üB
13 ìsû┌é┼é═üAăé╠âSü[âïé≡Ä└ìsé╡é▄é╖üBexec-rule é⌐éτ now-state é╠ê╩Æué╔
éáéΘâSü[âïé≡ĵéΦÅoé╡é─üAmake-env é┼Ä└ìsè┬ï½é≡ì∞ɼé╡é─ exec-env é╔âZâbâg
é╡é▄é╖üBLisp é┼é═âèâXâgé╠ùvæfé≡ 0 é⌐éτÉöéªéΘé╠é┼üAnow-state é¬Äƒé╠âSü[âï
é≡Äwé╖é▒é╞é╔Æìê╙é╡é─é¡é╛é│éóüBé╗é╠îπüAâïü[âvé╠ɵô¬é╔û▀éΦüAexec-clasue é¬
ò]ë┐é│éΩüAÉVé╡éóè┬ï½é┼âSü[âïé╞É▀é¬Å╞ìçé│éΩé▄é╖üB
exec-body é╠ô«ì∞é═Å¡üXô∩é╡éóé╠é┼üAæOé╔Éαû╛é╡é╜è┬ï½é╠ô«ì∞É}é≡ÄQìlé╔üA
é╢é┴é¡éΦé╞ìléªé─é¡é╛é│éóüB
ü¢âCâôâ^ü[âtâFü[âXé╠ì∞ɼ
ì┼îπé╔üAâfü[â^é≡âtâ@âCâïé⌐éτô╟é▌ì₧é▐ load-data é╞üAÄ┐ûΓé≡Ä≤é»òté»éΘè╓
Éö Q é≡ì∞éΦé▄é╖üB
List 45 : âfü[â^é╠âìü[âh
1 (defun load-data (filename)
2 (let (clause)
3 (with-open-file (in filename "r")
4 (while (setq clause (read in nil))
5 (assert clause)))))
âtâ@âCâïé╔é═üAÉ▀ ((ÅqîΩ ê°Éö ... ê°Éö) ... ) é¬ÆΦï`é│éΩé─éóéΘé▒é╞é≡æO
Ʊé╞é╡é─éóéΘé╠é┼üAâìü[âhë┬ö\é╚âtâ@âCâïé⌐â`âFâbâNé╡é─éóé╚éóé▒é╞é╔Æìê╙é╡é─
é¡é╛é│éóüBÅêù¥ôαùeé═è╚ÆPé┼é╖é╦üBâtâ@âCâïé≡âèü[âhâIü[âvâôé╡é─üAread é┼É▀
é≡ô╟é▌ì₧é▌üAé╗éΩé≡ assert é┼æ«É½âèâXâgé╔âZâbâgé╡é▄é╖üB
ăé═üAÄ┐ûΓé≡Ä≤é»òté»éΘè╓Éö Q é┼é╖üB
List 46 : Ä┐ûΓé≡Ä≤é»òté»éΘ
1 (defun Q (question)
2 (let* ((rule (make-rule question))
3 (env (make-env (slot-value rule 'clause)))
4 result)
5 (while (listp (setq result (exec-clause env)))
6 (dolist (var (slot-value rule 'var-list) (terpri))
7 (format t "~A = ~A\n" var (variable-value var))))))
é▄é╕üAmake-rule é┼Ä┐ûΓ question é≡ Rule é╠âCâôâXâ^âôâXé╔ò╧è╖é╡é▄é╖üBé▒
é╠Ä₧üAì\ò╢é╠â`âFâbâNé¬ìséφéΩé▄é╖üBăé╔üAé▒é╠Ä┐ûΓ rule é╔æ╬ë₧é╖éΘÄ└ìsè┬ï½
env é≡ make-env é┼ì∞ɼé╡é▄é╖üBîπé═üAé▒é╠ env é╔ exec-clause é≡ôKùpé╖éΘé▒
é╞é┼üAÄ┐ûΓé╞âfü[â^âxü[âXé≡Å╞ìçé╡é▄é╖üBôÜéªé¬î⌐é┬é⌐éΩé╬üAÄ┐ûΓé┼ÄgéφéΩé─éó
éΘò╧Éöé╠ë≡é≡ò\Īé╡é▄é╖üBò╧ÉöâèâXâgé═ rule é╠âXâìâbâg var-list é⌐éτïüé▀éΘ
é▒é╞é¬é┼é½é▄é╖é╦üBé╗é╠Ælé═ variable-value é≡î─é╤Åoé╣é╬ïüé▀éΘé▒é╞é¬é┼é½é▄
é╖üBè╓Éö Q é═üAProlog é╞êßé┴é─üAû│Å≡îÅé╔ì─ÄÄìsé≡ìséñé▒é╞é╔Æìê╙é╡é─é¡é╛é│
éóüB
é▒éΩé┼âvâìâOâëâÇé═è«É¼é┼é╖üBâvâìâOâëâÇé═âtâ@âCâï EXPERT.VL é╔èiö[é│éΩ
é─éóé▄é╖üBé▒éΩé⌐éτüAè╚ÆPé╚Ä└ìsùßé≡î⌐é─éóé¡é▒é╞é╔é╡é▄é╡éσéñüB
üiédénéeüj